home *** CD-ROM | disk | FTP | other *** search
/ The Sunday Times: The Month 2004 August / The Sunday Times - The Month 2004-08.iso / pc / engine / shell / shell.swf / scripts / DefineSprite_55 / frame_1 / DoAction.as
Encoding:
Text File  |  2004-07-06  |  12.0 KB  |  570 lines

  1. function childLockSet(val)
  2. {
  3.    makeChildren(ndParent,true);
  4. }
  5. function make(section)
  6. {
  7.    active = true;
  8.    arrParentIndex = [];
  9.    SECTION_COLOR = Tardis.Colors.getHex(section);
  10.    SECTION_HALF_COLOR = Tardis.Colors.getHex(section + "50");
  11.    mc_title.txt.textColor = SECTION_COLOR;
  12.    mc_up.clr.setRGB(SECTION_HALF_COLOR);
  13.    xmlMenu = new XML();
  14.    xmlMenu.onLoad = build;
  15.    xmlMenu.load(Tardis.ASSETS_FOLDER + "xml/sections/" + section + ".xml");
  16. }
  17. function clearUp()
  18. {
  19.    mc_root.removeMovieClip();
  20.    delete mc_root;
  21.    delete mc_lock;
  22.    delete xmlMenu;
  23.    delete ItemHome;
  24.    delete ndPromo;
  25.    delete mcPromo;
  26.    delete ndParent;
  27.    animating = false;
  28.    hide();
  29. }
  30. function hide()
  31. {
  32.    _visible = false;
  33.    active = false;
  34. }
  35. function doOver(nm)
  36. {
  37.    mc_root["mc_i_" + nm].onRollOver(true);
  38. }
  39. function doOut(nm)
  40. {
  41.    mc_root["mc_i_" + nm].onRollOut(true);
  42. }
  43. function doUp(nm)
  44. {
  45.    mc_root["mc_i_" + nm].onRelease(true);
  46. }
  47. function setTitle(str)
  48. {
  49.    with(mc_title)
  50.    {
  51.       txt.htmlText = str.replace("\\n","<br>");
  52.       txt.textColor = SECTION_COLOR;
  53.       txt.resize();
  54.    }
  55. }
  56. function build()
  57. {
  58.    var ndRoot = xmlMenu.firstChild;
  59.    var ndStyle = ndRoot.byName("style");
  60.    strDefault = ndStyle.attributes["default"];
  61.    strDefaultUp = ndStyle.attributes.up;
  62.    ItemHome = ndRoot.byName("items").firstChild;
  63.    _visible = true;
  64.    makeChildren(ItemHome);
  65.    onReady();
  66. }
  67. function clearAll()
  68. {
  69.    mc_root.removeMovieClip();
  70. }
  71. function makeChildren(nd, blnDontLoadPage)
  72. {
  73.    var fadeItem = function(obj)
  74.    {
  75.       obj._alpha = 0;
  76.       obj.i = (i + 1) * 2;
  77.       if(obj.onEnterFrame != null)
  78.       {
  79.          trace("ERROR");
  80.       }
  81.       obj.onEnterFrame = itemFadeEnterFrame;
  82.    };
  83.    var createItem = function(strName)
  84.    {
  85.       var mc = mc_root.createEmptyMovieClip(strName,++mc_root.depth);
  86.       mc.createTextField("txt",0,0,0,167,10);
  87.       var strLabel = node.attributes.label.toString().replace("\\n","<br>");
  88.       with(mc.txt)
  89.       {
  90.          embedFonts = true;
  91.          selectable = false;
  92.          wordWrap = true;
  93.          html = true;
  94.          autoSize = "left";
  95.          htmlText = "<font face=\"TardisFGDemi\" size=\"" + nmTextSize + "\">" + strLabel + "</font>";
  96.          textColor = SECTION_HALF_COLOR;
  97.       }
  98.       mc.index = i;
  99.       if(i > 0)
  100.       {
  101.          var mc_p = mc_root["mc_i_" + (i - 1)];
  102.          mc._y = mc_p._y + mc_p._height + PADDING;
  103.       }
  104.       fadeItem(mc);
  105.       mc.sound = node.attributes.type != "html" ? "ContentLink" : "WebLink";
  106.       return mc;
  107.    };
  108.    if(nd == Tardis.ActiveItem && nd.attributes.type == "promo")
  109.    {
  110.       nd = Tardis.ActiveItem = ndPromo;
  111.    }
  112.    nmFading = 0;
  113.    objLastClicked = null;
  114.    clearAll();
  115.    if(nd == ItemHome)
  116.    {
  117.       setTitle(strDefault);
  118.       mc_up.hide();
  119.    }
  120.    else
  121.    {
  122.       setTitle(nd.attributes.label);
  123.       mc_up.show();
  124.    }
  125.    ndParent = nd;
  126.    this.createEmptyMovieClip("mc_root",++depth);
  127.    mc_root._x = 8;
  128.    if(nd.attributes.hidenavtitle == "true")
  129.    {
  130.       mc_root._y = 12;
  131.       setTitle("");
  132.    }
  133.    else
  134.    {
  135.       mc_root._y = mc_title._y + mc_title._height + 2;
  136.    }
  137.    nmItems = nd.childNodes.length;
  138.    var nmSpacingForItems = nd.attributes.spacingforitems;
  139.    nmSpacingForItems != null ? 0 : (nmSpacingForItems = nmItems);
  140.    if(nmSpacingForItems > 15)
  141.    {
  142.       padding = -6;
  143.       mc_root._y -= 6;
  144.    }
  145.    else if(nmSpacingForItems > 10)
  146.    {
  147.       padding = -3;
  148.    }
  149.    else
  150.    {
  151.       padding = 0;
  152.    }
  153.    var strPadding = nd.attributes.padding;
  154.    if(strPadding != null)
  155.    {
  156.       padding = parseInt(strPadding);
  157.    }
  158.    var strFontSize = nd.attributes.fontsize;
  159.    var nmTextSize = strFontSize == null ? (nmItems <= 15 ? 12 : 11) : parseInt(strFontSize);
  160.    var nmLeading = -1;
  161.    var strUpText;
  162.    var strParentUpText;
  163.    if(nd.parentNode == ItemHome)
  164.    {
  165.       strUpText = strDefaultUp;
  166.    }
  167.    else
  168.    {
  169.       strParentUpText = nd.parentNode.attributes.up;
  170.       if(strParentUpText != null)
  171.       {
  172.          strUpText = strParentUpText;
  173.       }
  174.       else
  175.       {
  176.          strUpText = nd.parentNode.attributes.label;
  177.       }
  178.    }
  179.    mc_up.txt.text = strUpText;
  180.    var node;
  181.    var strType;
  182.    var mc;
  183.    var i = 0;
  184.    while(i < nmItems)
  185.    {
  186.       node = nd.childNodes[i];
  187.       node.index = i;
  188.       mc = createItem("mc_i_" + i);
  189.       strType = node.attributes.type;
  190.       if(strType == "promo")
  191.       {
  192.          mc.onRollOver = pOver;
  193.          mc.onRollOut = pOut;
  194.          mc.onRelease = rUp;
  195.          mcPromo = mc;
  196.          mc.node = node;
  197.       }
  198.       else if(strType == "semiOverlay")
  199.       {
  200.          trace("-- I\'ve got a semi");
  201.          mc.onRollOver = rOver;
  202.          mc.onRollOut = rOut;
  203.          mc.onRelease = rUp;
  204.          mc.node = node;
  205.       }
  206.       else if(strType == "locallink")
  207.       {
  208.          mc.onRollOver = rOver;
  209.          mc.onRollOut = rOut;
  210.          mc.onRelease = lUp;
  211.          mcPromo = mc;
  212.          mc.node = node;
  213.       }
  214.       else
  215.       {
  216.          mc.onRollOver = rOver;
  217.          mc.onRollOut = rOut;
  218.          mc.onRelease = rUp;
  219.          mc.node = node;
  220.          if(strType == "lock")
  221.          {
  222.             mc_lock = mc;
  223.          }
  224.       }
  225.       if(Tardis.ChildLock.active == true && (node.attributes.type == "html" || node.attributes.type == "promo"))
  226.       {
  227.          mc._y -= mc._height + PADDING;
  228.          mc._visible = false;
  229.       }
  230.       i++;
  231.    }
  232.    _xscale = 100;
  233.    if(nd.attributes.type == null && nd.firstChild.hasChildNodes() != true && blnDontLoadPage != true)
  234.    {
  235.       mc_root.mc_i_0.onRelease(null,true);
  236.    }
  237.    animating = true;
  238. }
  239. function rUp(fromContent, blnSilent)
  240. {
  241.    if(this == objLastClicked)
  242.    {
  243.       return undefined;
  244.    }
  245.    if(blnSilent == null)
  246.    {
  247.       Tardis.SFX.play(this.sound + "Click");
  248.    }
  249.    loadItem(this.node,0,this);
  250.    if(this.node.attributes.type != "inactive" && this.node.childNodes.length > 0)
  251.    {
  252.       arrParentIndex.push(this.index);
  253.       ndNext = this.node;
  254.       objLastClicked = this;
  255.       animating = true;
  256.       fadeDownOthers();
  257.       fadeDownFinished();
  258.    }
  259.    else
  260.    {
  261.       animating = false;
  262.       if(blnSilent == null)
  263.       {
  264.          onComplete();
  265.       }
  266.    }
  267. }
  268. function rOver(fromContent)
  269. {
  270.    if(this != objLastClicked)
  271.    {
  272.       Tardis.SFX.play(this.sound + "Over");
  273.       if(fromContent != true)
  274.       {
  275.          EB.broadcastMessage("doOver",this.index);
  276.       }
  277.       this.txt.textColor = SECTION_COLOR;
  278.    }
  279. }
  280. function rOut(fromContent)
  281. {
  282.    if(this != objLastClicked)
  283.    {
  284.       if(fromContent != true)
  285.       {
  286.          EB.broadcastMessage("doOut",this.index);
  287.       }
  288.       this.txt.textColor = SECTION_HALF_COLOR;
  289.    }
  290. }
  291. function itemFadeEnterFrame()
  292. {
  293.    with(this)
  294.    {
  295.       i--;
  296.       if(i <= 0)
  297.       {
  298.          _alpha += 100;
  299.          if(_alpha >= 100)
  300.          {
  301.             onEnterFrame = null;
  302.             fadeUpFinished();
  303.          }
  304.       }
  305.    }
  306. }
  307. function fadeUpFinished()
  308. {
  309.    nmFading++;
  310.    if(nmFading == nmItems)
  311.    {
  312.       animating = false;
  313.       onComplete();
  314.    }
  315. }
  316. function fadeDownOthers()
  317. {
  318.    nmFading = 0;
  319.    var mc;
  320.    var i = 0;
  321.    while(i < nmItems)
  322.    {
  323.       mc = mc_root["mc_i_" + i];
  324.       if(mc != objLastClicked)
  325.       {
  326.          mc.i = (len - i + 1) * 2;
  327.          if(mc.onEnterFrame != null)
  328.          {
  329.             trace("ERROR!");
  330.          }
  331.          mc.onEnterFrame = itemFadeUpEnterFrame;
  332.       }
  333.       i++;
  334.    }
  335. }
  336. function fadeDownFinished()
  337. {
  338.    nmFading++;
  339.    if(nmFading == nmItems)
  340.    {
  341.       makeChildren(ndNext);
  342.    }
  343. }
  344. function itemFadeUpEnterFrame()
  345. {
  346.    with(this)
  347.    {
  348.       i--;
  349.       if(i <= 0)
  350.       {
  351.          _alpha -= 40;
  352.          if(_alpha <= 0)
  353.          {
  354.             onEnterFrame = null;
  355.             fadeDownFinished();
  356.          }
  357.       }
  358.    }
  359. }
  360. function doPromoUp()
  361. {
  362.    if(typeof mcPromo == "movieclip")
  363.    {
  364.       mcPromo.onRelease(true);
  365.    }
  366.    else
  367.    {
  368.       Tardis.itemGo(ndPromo);
  369.    }
  370. }
  371. function doPromoOver()
  372. {
  373.    mcPromo.onRollOver(true);
  374. }
  375. function doPromoOut()
  376. {
  377.    mcPromo.onRollOut(true);
  378. }
  379. function pOver(fromContent)
  380. {
  381.    if(this != objLastClicked)
  382.    {
  383.       Tardis.SFX.play(this.sound + "Over");
  384.       if(fromContent != true)
  385.       {
  386.          EB.broadcastMessage("doPromoOver");
  387.       }
  388.       this.txt.textColor = SECTION_COLOR;
  389.    }
  390. }
  391. function pOut(fromContent)
  392. {
  393.    if(this != objLastClicked)
  394.    {
  395.       if(fromContent != true)
  396.       {
  397.          EB.broadcastMessage("doPromoOut");
  398.       }
  399.       this.txt.textColor = SECTION_HALF_COLOR;
  400.    }
  401. }
  402. function doAdvertUp(ndAdvert)
  403. {
  404.    if(typeof mcAdvert == "movieclip")
  405.    {
  406.       mcAdvert.onRelease(true);
  407.    }
  408.    else
  409.    {
  410.       var obj = new Object();
  411.       obj.filename = ndAdvert.attributes.filename;
  412.       obj.strType = ndAdvert.attributes.category;
  413.       obj.disableLevel = ndAdvert.attributes.disableLevel;
  414.       obj.trackingID = ndAdvert.attributes.trackingID;
  415.       obj.header = "default";
  416.       obj.closeBut = "advert";
  417.       Tardis.OverlayController.addOverlay(obj);
  418.    }
  419. }
  420. function doAdvertOver()
  421. {
  422.    mcPromo.onRollOver(true);
  423. }
  424. function doAdvertOut()
  425. {
  426.    mcPromo.onRollOut(true);
  427. }
  428. function lUp()
  429. {
  430.    if(blnSilent == null)
  431.    {
  432.       Tardis.SFX.play(this.sound + "Click");
  433.    }
  434.    loadItem(this.node,0,this);
  435.    var file = this.node.attributes.file;
  436.    getURL("Lingo:Flsh_openLocalLink(\"" + (Tardis.ASSETS_FOLDER + file) + "\")","");
  437.    animating = false;
  438.    if(blnSilent == null)
  439.    {
  440.       onComplete();
  441.    }
  442. }
  443. hide();
  444. stop();
  445. o = ASBroadcaster;
  446. o._broadcastMessage = function()
  447. {
  448.    var a = this._listeners.concat();
  449.    var e = arguments.shift();
  450.    for(var i in a)
  451.    {
  452.       a[i][e].apply(a[i],arguments);
  453.    }
  454. };
  455. o.addListener = function(obj)
  456. {
  457.    var a = this._listeners;
  458.    var i = a.length;
  459.    a[-1] = obj;
  460.    while(a[--i] != obj)
  461.    {
  462.    }
  463.    delete a[-1];
  464.    if(i < 0)
  465.    {
  466.       a.unshift(obj);
  467.       this.broadcastMessage = ASBroadcaster._broadcastMessage;
  468.       return true;
  469.    }
  470.    return false;
  471. };
  472. o.removeListener = function(obj)
  473. {
  474.    var a = this._listeners;
  475.    var i = a.length;
  476.    a[-1] = obj;
  477.    while(a[--i] != obj)
  478.    {
  479.    }
  480.    delete a[-1];
  481.    if(i >= 0)
  482.    {
  483.       a.splice(i,1);
  484.       if(a.length == 0)
  485.       {
  486.          this.broadcastMessage = undefined;
  487.       }
  488.       return true;
  489.    }
  490.    return false;
  491. };
  492. o.initialize = function(obj)
  493. {
  494.    obj.broadcastMessage = undefined;
  495.    obj.addListener = AsBroadcaster.addListener;
  496.    obj.removeListener = AsBroadcaster.removeListener;
  497.    obj._listeners = [];
  498.    AsSetPropFlags(obj,"broadcastMessage,addListener,removeListener,_listeners",131);
  499. };
  500. ASSetPropFlags(o,null,131);
  501. delete o;
  502. EB = {};
  503. ASBroadcaster.initialize(EB);
  504. active = false;
  505. animating = false;
  506. Tardis.ChildLock.EB.addListener(this);
  507. DEFAULT_COLOR = 12235927;
  508. with(mc_title.txt)
  509. {
  510.    autoSize = "left";
  511.    wordWrap = true;
  512. }
  513. mc_up.clr = new Color(mc_up);
  514. mc_up.onRollOver = function()
  515. {
  516.    Tardis.SFX.play("NavOver");
  517.    this.clr.setRGB(SECTION_COLOR);
  518. };
  519. mc_up.onRollOut = function()
  520. {
  521.    this.clr.setRGB(SECTION_HALF_COLOR);
  522. };
  523. mc_up.onRelease = function()
  524. {
  525.    if(animating == true)
  526.    {
  527.       return undefined;
  528.    }
  529.    Tardis.SFX.play("NavClick");
  530.    clearAll();
  531.    var ndUp = ndParent.parentNode;
  532.    trace("ndUp:" + ndUp);
  533.    Tardis.itemGo(ndUp);
  534.    makeChildren(ndUp);
  535.    arrParentIndex.pop();
  536. };
  537. mc_up.show = function()
  538. {
  539.    this._visible = true;
  540. };
  541. mc_up.hide = function()
  542. {
  543.    this._visible = false;
  544. };
  545. mc_up.hide();
  546. loadItem = function(node, calledFromCredits, mcItem)
  547. {
  548.    if(node.attributes.type == "locallink")
  549.    {
  550.       Tardis.localItemGo();
  551.    }
  552.    else
  553.    {
  554.       if(Tardis.itemGo(node) == true)
  555.       {
  556.          mcItem.txt.textColor = SECTION_COLOR;
  557.          objLastClicked.txt.textColor = SECTION_HALF_COLOR;
  558.          objLastClicked = mcItem;
  559.       }
  560.       if(calledFromCredits == 1)
  561.       {
  562.          animating = false;
  563.          onComplete();
  564.       }
  565.    }
  566. };
  567. var nmFading = 0;
  568. var mcPromo;
  569. var mcAdvert;
  570.